package cn.edu.scau.cmi.ChenKaihui.client;

import java.net.URL;
import java.util.ResourceBundle;

import cn.edu.scau.cmi.ChenKaihui.domain.Insurance;
import cn.edu.scau.cmi.ChenKaihui.simpleFactoryMethod.InsuranceFactory;
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.ChoiceBox;
import javafx.scene.control.TextArea;
import javafx.stage.Stage;

public class SimpleFactoryMethodClient extends Application implements Initializable {

	@FXML
	public ChoiceBox<String> insuranceChoiceBox;

	@FXML
	public TextArea textArea;

	@Override
	public void initialize(URL location, ResourceBundle resources) {
		ObservableList<String> options = FXCollections.observableArrayList("身体受伤", "汽车损坏", "人员伤亡", "多种事故");
		insuranceChoiceBox.setValue("身体受伤");
		insuranceChoiceBox.setItems(options);
	}

	public void displayMessage() {
		String str = insuranceChoiceBox.getValue();
		Insurance insurance = InsuranceFactory.getInstance(str);
		textArea.setText(insurance.showInsurance());
	}

	@Override
	public void start(Stage primaryStage) throws Exception {
		Parent root = FXMLLoader.load(getClass().getResource("../sample/sample.fxml"));
		primaryStage.setTitle("简单工厂模式");
		primaryStage.setScene(new Scene(root, 800, 800));
		primaryStage.setResizable(false);
		primaryStage.show();
	}

	public static void main(String[] args) {
		launch(args);
	}

}
